package com.quantum.ui.component
{

	import com.quantum.ui.component.checkboxdatagrid.CheckBoxDataGridColumn;

	import mx.controls.AdvancedDataGrid;
	import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
	import mx.controls.listClasses.IListItemRenderer;
	import mx.core.ClassFactory;
	import mx.core.IFactory;
	import mx.core.mx_internal;

	use namespace mx_internal;

	[Event(name="selectChanged", type="flash.events.Event")]

	public class CheckBoxDataGrid extends SimpleDataGrid
	{
		public function CheckBoxDataGrid()
		{
			this.allowMultipleSelection=true;
			super();
		}

		private var _userColumns:Array;

		private var _checkBoxHeaderItemRenderer:IFactory;

		/**
		 *  The class factory that will be used to create the header of checkbox column.
		 */
		public function get checkBoxHeaderItemRenderer():IFactory
		{
			return _checkBoxHeaderItemRenderer;
		}

		public function set checkBoxHeaderItemRenderer(value:IFactory):void
		{
			_checkBoxHeaderItemRenderer=value;
			this.columns=_userColumns;
		}

		public var headerCheckBoxEnabled:Boolean=true;

		public function get userColumns():Array
		{
			return _userColumns;
		}

		override public function set columns(value:Array):void
		{
			_userColumns=value;
			var columns:Array=value.concat();
			var chkBoxClmn:CheckBoxDataGridColumn=new CheckBoxDataGridColumn();
			chkBoxClmn.headerRenderer=checkBoxHeaderItemRenderer;
			columns.splice(0, 0, chkBoxClmn);
			super.columns=columns;
		}

		override protected function selectItem(item:IListItemRenderer, shiftKey:Boolean, ctrlKey:Boolean, transition:Boolean=true):Boolean
		{
			return super.selectItem(item, shiftKey, true, transition);
		}

//      override protected function drawItem(item:IListItemRenderer,
//                                           selected:Boolean=false,
//                                           highlighted:Boolean=false,
//                                           caret:Boolean=false,
//                                           transition:Boolean=false):void {
//         super.drawItem(item, false, highlighted, caret, transition);
//      }
	}
}
